var gulp = require('gulp');
var sass = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    minifycss = require('gulp-minify-css'),
    uglify = require('gulp-uglify'),
    clean = require('gulp-clean'),
    webpack = require('gulp-webpack');
var webpackConfig = require('./webpack.config');
gulp.task('default', ['clean', 'watch', 'sass:watch', 'sass', 'webpack']);

// gulp.task('sass:watch', function() {
//     gulp.watch('src/pages/*/*.scss', ['sass']);
//     gulp.watch('src/directives/*/*.scss', ['sass']);
// });
// gulp.task('sass', function() {
//     gulp.src(['src/pages/**/*.scss'])
//         .pipe(sass.sync().on('error', sass.logError))
//         .pipe(minifycss())
//         .pipe(gulp.dest('build/pages'));
// });

gulp.task('sass', function() {
    gulp.src('*.scss')
        .pipe(sass({
            sourceComments: true,
            outputStyle: 'expanded',
            errLogToConsole: true
        }))
        .pipe(gulp.dest('dest'));
});

gulp.task('watch', ['sass'], function() {
    var sassWatcher = gulp.watch('*.scss', ['sass']);
    gulp.watch('src/pages/*/*.scss', ['sass']);
    gulp.watch('src/directives/*/*.scss', ['sass']);
});
gulp.task('clean', function() {
    return gulp.src(['build/pages'], {
            read: false
        })
        .pipe(clean());
});
gulp.task("webpack", function() {
    return gulp
        .src('./')
        .pipe(webpack(webpackConfig))
        //.pipe(uglify())
        .pipe(gulp.dest('./build/pages'));
});
gulp.task('watch', function() {
    gulp.watch('src/directives/*/*.js', ['webpack']);
    gulp.watch('src/pages/*/*.js', ['webpack']);
});